package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class Comments extends BaseDomain{

    public static final int STATE_UNREAD = 1;  // 未读
    public static final int STATE_READ = 0;  // 已读

    private Long user_id;  // 评论的用户id

    //private Strategy target;  // 评论的目标
    private Long target_id;
    private String targetname;

    private Integer state = 1;  // 评论的状态

    private Integer admire_count;  // 点赞数

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date create_time;  // 评论创建时间

    private Date update_time;  // 评论更新时间

    private String username;  // 评论者的用户名

    private String headImgUrl;  // 评论者的头像

    private String hot_value;  // 评论的热度

    private Integer type;  // 评论的类型 备用0 /评论 1 / 私信 2 / @ 3/ 赞 4

    private String content;  // 评论内容

    public String getStateDisplay(){
        if(state == 0){
            return "已读";
        }else if (state == 1){
            return "未读";
        }else{
            return "";
        }
    }

    public String getJsonString(){
        Map<String, Object> map = new HashMap<>();
        map.put("id", getId());
        map.put("userId",user_id);
        map.put("username",username);
        /*if(target != null) {
            map.put("StrategyId", target.getId());
            map.put("StrategyName",target.getTitle());
        }*/
        map.put("targetId",target_id);
        map.put("targetName",targetname);
        map.put("createTime", DateUtil.date2string(create_time,"yyyy-MM-dd HH:mm:ss"));
        map.put("update_time",update_time);
        map.put("headImgUrl",headImgUrl);
        map.put("content",content);
        return JSONUtil.toJSONString(map);
    }
}